<?php
/**
 * PHP version 5
 * @copyright  Samsun Xu 2009
 * @package    Frontend
 * @license    LGPL
 * @get product list
 */
session_start();
require('system/initialize.php');

class change_currency
{
	public function run()
	{
		if ($_POST['cur'] == 'USD'){
			$str_html = "<div class=\"payment_module\">
					<!--<input type=\"radio\" name=\"payment\" value=\"\" class=\"radio\" />-->
					<!--<a title=\"Pay with PayPal International\" href=\"javascript:$('#paypal_form').submit();\">-->
					<a title=\"Pay with PayPal International\" href=\"".$this->Environment->base."validation.html?method=Paypal\">
					<img alt=\"Pay with PayPal International\" src=\"images/paypal/paypal.gif\"/>
					<p>All payment will be deducted from your account in US$. </p>
					</a>
					</div>";
			echo $str_html;exit;
		}else{
			$this->setDB();
			$is_shanghai_only = false;
			$sql = "SELECT * FROM `tl_address_book` WHERE `id`=".$_SESSION['ORDER']['address_shipping'];
			$res = @mysql_query($sql);
			$result = @mysql_fetch_assoc($res);
			
			if ($result['country'] == 'cn'){
				$sql = "SELECT * 
						FROM `china_city` 
						LEFT JOIN `china_province` ON `china_province`.`id`=`china_city`.`pid`
						WHERE `china_city`.`id`='".$result['city']."'";
				$res = @mysql_query($sql);
				$result = @mysql_fetch_assoc($res);	
				
				if ($result['province_en'] == 'Shanghai'){
					$is_shanghai_only = true;
				}
			}
			
			$str_html = (($is_shanghai_only) ? "<div class=\"payment_module delivery_cod\">
					<!--<input type=\"radio\" name=\"payment\" value=\"\" class=\"radio\" />-->
					<a title=\"Pay with cash on delivery (COD)\" href=\"".$this->Environment->base."validation.html?method=COD\"><h4>Pay on delivery (Shanghai Only)</h4>
					<!--<img style=\"float: left;\" alt=\"Pay with cash on delivery (COD)\" src=\"".$this->Environment->base."images/cashondelivery/cashondelivery.gif\"/>-->
					<p>You pay for the merchandise upon delivery with cash, OR by China Unionpay bank card.</p>
					<!--<p>* Note: Shanghai Only. Please call +86 21 65353451 if you have questions.</p>-->
					</a>
					</div>" : "") . "<div class=\"payment_module\">
					<a title=\"Pay with Alipay\" href=\"".$this->Environment->base."validation.html?method=Alipay\">
					<img alt=\"Pay with Alipay\" src=\"images/alipay/alipay_2.gif\"/>
					<p>All payment will be deducted from your account in RMB. </p>
					</a>
					</div>";
			echo $str_html;exit;
		}
	}
	
	private function setDB()
	{
		$strHost = $GLOBALS['TL_CONFIG']['dbHost'];
		if($GLOBALS['TL_CONFIG']['dbPort']){
			$strHost .= ':' . $GLOBALS['TL_CONFIG']['dbPort'];
		}

		if($GLOBALS['TL_CONFIG']['dbPconnect']){
			$resConnection = @mysql_pconnect($strHost, $GLOBALS['TL_CONFIG']['dbUser'], $GLOBALS['TL_CONFIG']['dbPass']);
		}else{
			$resConnection = @mysql_connect($strHost, $GLOBALS['TL_CONFIG']['dbUser'], $GLOBALS['TL_CONFIG']['dbPass']);
		}

		if (is_resource($resConnection)){
			@mysql_query("SET sql_mode=''", $resConnection);
			@mysql_query("SET NAMES " . $GLOBALS['TL_CONFIG']['dbCharset'], $resConnection);
			@mysql_select_db($GLOBALS['TL_CONFIG']['dbDatabase'], $resConnection);
		}
	}
}

$objGetRd = new change_currency();
$objGetRd->run();